home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / ultqsrc.zip / AI.QC next >
Text File  |  1996-09-25  |  20KB  |  826 lines

  1. void() ai_stand;
  2.  
  3. void() movetarget_f;
  4. void() t_movetarget;
  5. void() knight_walk1;
  6. void() knight_bow6;
  7. void() knight_bow1;
  8. /*
  9.  
  10. .enemy
  11. Will be world if not currently angry at anyone.
  12.  
  13. .movetarget
  14. The next path spot to walk toward.  If .enemy, ignore .movetarget.
  15. When an enemy is killed, the monster will try to return to it's path.
  16.  
  17. .huntt_ime
  18. Set to time + something when the player is in sight, but movement straight for
  19. him is blocked.  This causes the monster to use wall following code for
  20. movement direction instead of sighting on the player.
  21.  
  22. .ideal_yaw
  23. A yaw angle of the intended direction, which will be turned towards at up
  24. to 45 deg / state.  If the enemy is in view and hunt_time is not active,
  25. this will be the exact line towards the enemy.
  26.  
  27. .pausetime
  28. A monster will leave it's stand state and head towards it's .movetarget when
  29. time > .pausetime.
  30.  
  31. walkmove(angle, speed) primitive is all or nothing
  32. */
  33.  
  34.  
  35. //
  36. // globals
  37. //
  38. float    current_yaw;
  39.  
  40. //
  41. // when a monster becomes angry at a player, that monster will be used
  42. // as the sight target the next frame so that monsters near that one
  43. // will wake up even if they wouldn't have noticed the player
  44. //
  45. entity    sight_entity;
  46. float    sight_entity_time;
  47.  
  48. float(float v) anglemod =
  49. {
  50.     while (v >= 360)
  51.         v = v - 360;
  52.     while (v < 0)
  53.         v = v + 360;
  54.     return v;
  55. };
  56.  
  57. /*
  58. ==============================================================================
  59.  
  60. MOVETARGET CODE
  61.  
  62. The angle of the movetarget effects standing and bowing direction, but has no effect on movement, which allways heads to the next target.
  63.  
  64. targetname
  65. must be present.  The name of this movetarget.
  66.  
  67. target
  68. the next spot to move to.  If not present, stop here for good.
  69.  
  70. pausetime
  71. The number of seconds to spend standing or bowing for path_stand or path_bow
  72.  
  73. ==============================================================================
  74. */
  75. void() movetarget_f =
  76. {
  77.     if (!self.targetname)
  78.         objerror ("monster_movetarget: no targetname");
  79.         
  80.     self.solid = SOLID_TRIGGER;
  81.     self.touch = t_movetarget;
  82.     setsize (self, '-8 -8 -8', '8 8 8');
  83.     
  84. };
  85.  
  86. /*QUAKED path_corner (0.5 0.3 0) (-8 -8 -8) (8 8 8)
  87. Monsters will continue walking towards the next target corner.
  88. */
  89. void() path_corner =
  90. {
  91.     movetarget_f ();
  92. };
  93.  
  94.  
  95. /*
  96. =============
  97. t_movetarget
  98.  
  99. Something has bumped into a movetarget.  If it is a monster
  100. moving towards it, change the next destination and continue.
  101. ==============
  102. */
  103. void() t_movetarget =
  104. {
  105. local entity    temp;
  106.  
  107.     if (other.movetarget != self)
  108.         return;
  109.     
  110.     if (other.enemy)
  111.         return;        // fighting, not following a path
  112.  
  113.     temp = self;
  114.     self = other;
  115.     other = temp;
  116.  
  117.         if (self.classname == "ogre")
  118.         sound (self, CHAN_VOICE, "ogre/ogdrag.wav", 1, ATTN_IDLE);// play chainsaw drag sound
  119.  
  120. //dprint ("t_movetarget\n");
  121.     self.goalentity = self.movetarget = find (world, targetname, other.target);
  122.     self.ideal_yaw = vectoyaw(self.goalentity.origin - self.origin);
  123.     if (!self.movetarget)
  124.     {
  125.         self.pausetime = time + 999999;
  126.         self.th_stand ();
  127.         return;
  128.     }
  129. };
  130.  
  131.  
  132.  
  133. //============================================================================
  134.  
  135. /*
  136. =============
  137. range
  138.  
  139. returns the range catagorization of an entity reletive to self
  140. 0    melee range, will become hostile even if back is turned
  141. 1    visibility and infront, or visibility and show hostile
  142. 2    infront and show hostile
  143. 3    only triggered by damage
  144. =============
  145. */
  146. float(entity targ) range =
  147. {
  148. local vector    spot1, spot2;
  149. local float        r;    
  150.     spot1 = self.origin + self.view_ofs;
  151.     spot2 = targ.origin + targ.view_ofs;
  152.     
  153.     r = vlen (spot1 - spot2);
  154.     if (r < 120)
  155.         return RANGE_MELEE;
  156.     if (r < 500)
  157.         return RANGE_NEAR;
  158.     if (r < 1000)
  159.         return RANGE_MID;
  160.     return RANGE_FAR;
  161. };
  162.  
  163. /*
  164. =============
  165. visible
  166.  
  167. returns 1 if the entity is visible to self, even if not infront ()
  168. =============
  169. */
  170. float (entity targ) visible =
  171. {
  172.     local vector    spot1, spot2;
  173.     
  174.     spot1 = self.origin + self.view_ofs;
  175.     spot2 = targ.origin + targ.view_ofs;
  176.     traceline (spot1, spot2, TRUE, self);    // see through other monsters
  177.     
  178.     if (trace_inopen && trace_inwater)
  179.         return FALSE;            // sight line crossed contents
  180.  
  181.     if (trace_fraction == 1)
  182.         return TRUE;
  183.     return FALSE;
  184. };
  185.  
  186.  
  187. /*
  188. =============
  189. infront
  190.  
  191. returns 1 if the entity is in front (in sight) of self
  192. =============
  193. */
  194. float(entity targ) infront =
  195. {
  196.     local vector    vec;
  197.     local float        dot;
  198.     
  199.     makevectors (self.angles);
  200.     vec = normalize (targ.origin - self.origin);
  201.     dot = vec * v_forward;
  202.     
  203.     if ( dot > 0.3)
  204.     {
  205.         return TRUE;
  206.     }
  207.     return FALSE;
  208. };
  209.  
  210.  
  211. //============================================================================
  212.  
  213. /*
  214. ===========
  215. ChangeYaw
  216.  
  217. Turns towards self.ideal_yaw at self.yaw_speed
  218. Sets the global variable current_yaw
  219. Called every 0.1 sec by monsters
  220. ============
  221. */
  222. /*
  223.  
  224. void() ChangeYaw =
  225. {
  226.     local float        ideal, move;
  227.  
  228. //current_yaw = self.ideal_yaw;
  229. // mod down the current angle
  230.     current_yaw = anglemod( self.angles_y );
  231.     ideal = self.ideal_yaw;
  232.     
  233.     if (current_yaw == ideal)
  234.         return;
  235.     
  236.     move = ideal - current_yaw;
  237.     if (ideal > current_yaw)
  238.     {
  239.         if (move > 180)
  240.             move = move - 360;
  241.     }
  242.     else
  243.     {
  244.         if (move < -180)
  245.             move = move + 360;
  246.     }
  247.         
  248.     if (move > 0)
  249.     {
  250.         if (move > self.yaw_speed)
  251.             move = self.yaw_speed;
  252.     }
  253.     else
  254.     {
  255.         if (move < 0-self.yaw_speed )
  256.             move = 0-self.yaw_speed;
  257.     }
  258.  
  259.     current_yaw = anglemod (current_yaw + move);
  260.  
  261.     self.angles_y = current_yaw;
  262. };
  263.  
  264. */
  265.  
  266.  
  267. //============================================================================
  268.  
  269. void() HuntTarget =
  270. {
  271.     self.goalentity = self.enemy;
  272.     self.think = self.th_run;
  273.     self.ideal_yaw = vectoyaw(self.enemy.origin - self.origin);
  274.     self.nextthink = time + 0.1;
  275.     SUB_AttackFinished (1);    // wait a while before first attack
  276. };
  277.         
  278. void() SightSound =
  279. {
  280. local float    rsnd;
  281.  
  282.         if (self.classname == "ogre") 
  283.         sound (self, CHAN_VOICE, "ogre/ogwake.wav", 1, ATTN_NORM);
  284.         else if (self.classname == "knight")
  285.         sound (self, CHAN_VOICE, "knight/ksight.wav", 1, ATTN_NORM);
  286.         else if (self.classname == "shambler")
  287.         sound (self, CHAN_VOICE, "shambler/ssight.wav", 1, ATTN_NORM);
  288.         else if (self.classname == "fiend")
  289.         sound (self, CHAN_VOICE, "demon/sight2.wav", 1, ATTN_NORM);
  290.         else if (self.classname == "scrag")
  291.         sound (self, CHAN_VOICE, "wizard/wsight.wav", 1, ATTN_NORM);
  292.         else if (self.classname == "zombie")
  293.         sound (self, CHAN_VOICE, "zombie/z_idle.wav", 1, ATTN_NORM);
  294.         else if (self.classname == "rottwieler")
  295.         sound (self, CHAN_VOICE, "dog/dsight.wav", 1, ATTN_NORM);
  296.         else if (self.classname == "hell knight")
  297.         sound (self, CHAN_VOICE, "hknight/sight1.wav", 1, ATTN_NORM);
  298.         else if (self.classname == "spawn")
  299.         sound (self, CHAN_VOICE, "blob/sight1.wav", 1, ATTN_NORM);
  300. //        else if (self.classname == "monster_vomit")
  301. //                sound (self, CHAN_VOICE, "vomitus/v_sight1.wav", 1, ATTN_NORM);
  302.         else if (self.classname == "enforcer")
  303.     {
  304.         rsnd = rint(random() * 3);            
  305.         if (rsnd == 1)
  306.             sound (self, CHAN_VOICE, "enforcer/sight1.wav", 1, ATTN_NORM);
  307.         else if (rsnd == 2)
  308.             sound (self, CHAN_VOICE, "enforcer/sight2.wav", 1, ATTN_NORM);
  309.         else if (rsnd == 0)
  310.             sound (self, CHAN_VOICE, "enforcer/sight3.wav", 1, ATTN_NORM);
  311.         else
  312.             sound (self, CHAN_VOICE, "enforcer/sight4.wav", 1, ATTN_NORM);
  313.     }
  314.         else if (self.classname == "grunt")
  315.         sound (self, CHAN_VOICE, "soldier/sight1.wav", 1, ATTN_NORM);
  316.         else if (self.classname == "vore")
  317.         sound (self, CHAN_VOICE, "shalrath/sight.wav", 1, ATTN_NORM);
  318. };
  319.  
  320. void() FoundTarget =
  321. {
  322.         if ((self.enemy.classname == "player" && self.enemy != self.controller) || (self.charmed && self.enemy != self.controller && self.enemy.classname == "player"))
  323.     {    // let other monsters see this monster for a while
  324.         sight_entity = self;
  325.         sight_entity_time = time;
  326.     }
  327.     
  328.     self.show_hostile = time + 1;        // wake up other monsters
  329.  
  330.     SightSound ();
  331.     HuntTarget ();
  332. };
  333.  
  334. /*
  335. ===========
  336. FindTarget
  337.  
  338. Self is currently not attacking anything, so try to find a target
  339.  
  340. Returns TRUE if an enemy was sighted
  341.  
  342. When a player fires a missile, the point of impact becomes a fakeplayer so
  343. that monsters that see the impact will respond as if they had seen the
  344. player.
  345.  
  346. To avoid spending too much time, only a single client (or fakeclient) is
  347. checked each frame.  This means multi player games will have slightly
  348. slower noticing monsters.
  349. ============
  350. */
  351. float() FindTarget =
  352. {
  353.         local entity    client,head;
  354.         local float             r,skip;
  355.  
  356. // if the first spawnflag bit is set, the monster will only wake up on
  357. // really seeing the player, not another monster getting angry
  358.  
  359. // spawnflags & 3 is a big hack, because zombie crucified used the first
  360. // spawn flag prior to the ambush flag, and I forgot about it, so the second
  361. // spawn flag works as well
  362. if (self.charmed)
  363. {
  364. //        if (self.controller.enemy != world && self.controller.enemy != self && self.controller.enemy.controller != self.controller && (self.controller.enemy.alive) && (self.enemy == world || self.enemy == self.controller))
  365. //               {
  366. //               self.enemy = self.controller.enemy;
  367. //               FoundTarget();
  368. //               return TRUE;
  369. //               }
  370.         if (self.enemy == world && self.classname != "spell")
  371.                 self.follow = TRUE;
  372.         else self.follow = FALSE;
  373.         head = findradius (self.origin, 1000);
  374.                 while(head)
  375.                 {
  376.                         if((head != self.controller || self.follow) && (head != self) && (head.alive) && (head != world) && (head != self) && (head.owner!=self)&&(!head.isfeign))
  377.                         {
  378.                         if ((!head.alive) && head.owner == self.owner)
  379.                                         {
  380.                                         if (self.classname == "spell")
  381.                                                 self.enemy = world;
  382.                                         else
  383.                                                 self.enemy = self.controller;
  384.                                         return FALSE;
  385.                                         }
  386.                         r = range(head);
  387.                         if ((range(head) != RANGE_FAR) && (visible (head)))
  388.                                 {
  389.                                 self.enemy = head;
  390.                                 if(self.enemy.controller == self.controller)
  391.                                    {
  392.                                    skip = FALSE;
  393.                                    if (self.enemy.enemy != world && self.enemy.enemy.alive && self.enemy.enemy != self.controller && self.enemy.enemy.controller != self.controller)
  394.                                         self.enemy = self.enemy.enemy;
  395.                                    else skip = TRUE;
  396.                                    }
  397.                                 if (skip == FALSE)
  398.                                 {
  399.                                 FoundTarget();
  400.                                 return TRUE;
  401.                                 }
  402.                                 }
  403.                         }
  404.                         head = head.chain;
  405.                 }
  406.         if (self.classname == "spell")
  407.                self.enemy = world;
  408.         else
  409.         {
  410.         self.enemy = self.controller;
  411.         self.oldenemy = self.controller;
  412.         }
  413.         return;
  414. }
  415. else if (sight_entity_time >= time - 0.1 && !(self.spawnflags & 3))
  416.     {
  417.                 client = sight_entity;
  418.                 if (client.enemy == self.enemy)
  419.             return;
  420.     }
  421. else
  422.     {
  423.                 client = checkclient ();
  424.                 if (!client)
  425.             return FALSE;    // current check entity isn't in PVS
  426.     }
  427.  
  428.         if(client.isfeign||(!client.alive))
  429.                 if(client.newholo.active&&visible(client.newholo))
  430.                         {
  431.                         self.enemy=client.newholo;
  432.                         FoundTarget();
  433.                         return TRUE;
  434.                         }
  435.                 else return FALSE;
  436.  
  437.     if (client == self.enemy)
  438.                 return FALSE;
  439.  
  440.         if (client.flags & FL_NOTARGET)
  441.                 return FALSE;
  442.  
  443.         if (client.items & IT_INVISIBILITY)
  444.         return FALSE;
  445.  
  446.     r = range (client);
  447.     if (r == RANGE_FAR)
  448.         return FALSE;
  449.         
  450.     if (!visible (client))
  451.                 return FALSE;
  452.  
  453.     if (r == RANGE_NEAR)
  454.     {
  455.         if (client.show_hostile < time && !infront (client))
  456.             return FALSE;
  457.     }
  458.     else if (r == RANGE_MID)
  459.     {
  460.         if ( /* client.show_hostile < time || */ !infront (client))
  461.             return FALSE;
  462.     }
  463. //
  464. // got one
  465. //
  466.         self.enemy = client;
  467.     if (self.enemy.classname != "player")
  468.     {
  469.         self.enemy = self.enemy.enemy;
  470.         if (self.enemy.classname != "player")
  471.         {
  472.             self.enemy = world;
  473.             return FALSE;
  474.         }
  475.     }
  476.     FoundTarget ();
  477.     return TRUE;
  478. };
  479.  
  480.  
  481. //=============================================================================
  482.  
  483. void(float dist) ai_forward =
  484. {
  485.     walkmove (self.angles_y, dist);
  486. };
  487.  
  488. void(float dist) ai_back =
  489. {
  490.     walkmove ( (self.angles_y+180), dist);
  491. };
  492.  
  493.  
  494. /*
  495. =============
  496. ai_pain
  497.  
  498. stagger back a bit
  499. =============
  500. */
  501. void(float dist) ai_pain =
  502. {
  503.  
  504.     ai_back (dist);
  505.  
  506.     local float    away;
  507.     
  508. if (random () < 0.2)
  509.         {
  510.     away = anglemod (vectoyaw (self.origin - self.enemy.origin)
  511.     + 180*(random()- 0.5) );
  512.     walkmove (away, dist);
  513.         }
  514. };
  515.  
  516. /*
  517. =============
  518. ai_painforward
  519.  
  520. stagger back a bit
  521. =============
  522. */
  523. void(float dist) ai_painforward =
  524. {
  525.     walkmove (self.ideal_yaw, dist);
  526. };
  527.  
  528. /*
  529. =============
  530. ai_walk
  531.  
  532. The monster is walking it's beat
  533. =============
  534. */
  535. void(float dist) ai_walk =
  536. {
  537.  
  538.         if (pointcontents(self.origin+'0 0 24') < -2 && pointcontents(self.origin+'0 0 24') > -5)
  539.               if (random () < 0.1)
  540.               DeathBubbles (1);
  541.  
  542.         if (self.watertype == CONTENT_LAVA)
  543.                        T_Damage (self,world, self.enemy, 5);
  544.         else if (self.watertype == CONTENT_SLIME)
  545.                        T_Damage (self,world, self.enemy, 1);
  546.  
  547.         if(self.bloodloss>0)
  548.                 Bleed();
  549. //        movedist = dist;
  550.  
  551.     // check for noticing a player
  552.     if (FindTarget ())
  553.         return;
  554.  
  555.     movetogoal (dist);
  556. };
  557.  
  558.  
  559. /*
  560. =============
  561. ai_stand
  562.  
  563. The monster is staying in one place for a while, with slight angle turns
  564. =============
  565. */
  566. void() ai_stand =
  567. {
  568.         if (pointcontents(self.origin+'0 0 24') < -2 && pointcontents(self.origin+'0 0 24') > -5)
  569.               if (random () < 0.1)
  570.               DeathBubbles (1);
  571.  
  572.         if (self.watertype == CONTENT_LAVA)
  573.                        T_Damage (self,world, self.enemy, 5);
  574.         else if (self.watertype == CONTENT_SLIME)
  575.                        T_Damage (self,world, self.enemy, 1);
  576.  
  577.         if(self.bloodloss>0)
  578.                 Bleed();
  579.  
  580.     if (FindTarget ())
  581.         return;
  582.     
  583.         if (time > self.pausetime)
  584.     {
  585.         self.th_walk ();
  586.         return;
  587.     }
  588.     
  589. // change angle slightly
  590. };
  591.  
  592. /*
  593. =============
  594. ai_turn
  595.  
  596. don't move, but turn towards ideal_yaw
  597. =============
  598. */
  599. void() ai_turn =
  600. {
  601.     if (FindTarget ())
  602.         return;
  603.     
  604.     ChangeYaw ();
  605. };
  606.  
  607. //=============================================================================
  608.  
  609. /*
  610. =============
  611. ChooseTurn
  612. =============
  613. */
  614. void(vector dest3) ChooseTurn =
  615. {
  616.     local vector    dir, newdir;
  617.     
  618.     dir = self.origin - dest3;
  619.  
  620.     newdir_x = trace_plane_normal_y;
  621.     newdir_y = 0 - trace_plane_normal_x;
  622.     newdir_z = 0;
  623.     
  624.     if (dir * newdir > 0)
  625.     {
  626.         dir_x = 0 - trace_plane_normal_y;
  627.         dir_y = trace_plane_normal_x;
  628.     }
  629.     else
  630.     {
  631.         dir_x = trace_plane_normal_y;
  632.         dir_y = 0 - trace_plane_normal_x;
  633.     }
  634.  
  635.     dir_z = 0;
  636.     self.ideal_yaw = vectoyaw(dir);    
  637. };
  638.  
  639. /*
  640. ============
  641. FacingIdeal
  642.  
  643. ============
  644. */
  645. float() FacingIdeal =
  646. {
  647.     local    float    delta;
  648.     
  649.     delta = anglemod(self.angles_y - self.ideal_yaw);
  650.     if (delta > 45 && delta < 315)
  651.         return FALSE;
  652.     return TRUE;
  653. };
  654.  
  655.  
  656. //=============================================================================
  657.  
  658. /*
  659. =============
  660. ai_run_melee
  661.  
  662. Turn and close until within an angle to launch a melee attack
  663. =============
  664. */
  665. void() ai_run_melee =
  666. {
  667.     self.ideal_yaw = enemy_yaw;
  668.     ChangeYaw ();
  669.  
  670.     if (FacingIdeal())
  671.     {
  672.         self.th_melee ();
  673.         self.attack_state = AS_STRAIGHT;
  674.     }
  675. };
  676.  
  677.  
  678. /*
  679. =============
  680. ai_run_missile
  681.  
  682. Turn in place until within an angle to launch a missile attack
  683. =============
  684. */
  685. void() ai_run_missile =
  686. {
  687.     self.ideal_yaw = enemy_yaw;
  688.     ChangeYaw ();
  689.     if (FacingIdeal())
  690.     {
  691.         self.th_missile ();
  692.         self.attack_state = AS_STRAIGHT;
  693.     }
  694. };
  695.  
  696.  
  697. /*
  698. =============
  699. ai_run_slide
  700.  
  701. Strafe sideways, but stay at aproximately the same range
  702. =============
  703. */
  704. void() ai_run_slide =
  705. {
  706.     local float    ofs;
  707.     
  708.     self.ideal_yaw = enemy_yaw;
  709.     ChangeYaw ();
  710.     if (self.lefty)
  711.         ofs = 90;
  712.     else
  713.         ofs = -90;
  714.     
  715.     if (walkmove (self.ideal_yaw + ofs, movedist))
  716.         return;
  717.         
  718.     self.lefty = 1 - self.lefty;
  719.     
  720.     walkmove (self.ideal_yaw - ofs, movedist);
  721. };
  722.  
  723.  
  724. /*
  725. =============
  726. ai_run
  727.  
  728. The monster has an enemy it is trying to kill
  729. =============
  730. */
  731. void(float dist) ai_run =
  732. {
  733.     local    vector    delta;
  734.     local    float    axis;
  735.     local    float    direct, ang_rint, ang_floor, ang_ceil;
  736.  
  737.         if (self.skin!=0)
  738.                 self.skin = 0;
  739.  
  740.         if (pointcontents(self.origin+'0 0 24') < -2 && pointcontents(self.origin+'0 0 24') > -5&&self.classname!="rotfish")
  741.               {
  742.               self.origin_z = self.origin_z + 2;
  743.               if (random () < 0.1)
  744.                       DeathBubbles (1);
  745.               }
  746.  
  747.         if (self.watertype == CONTENT_LAVA)
  748.                        T_Damage (self,world, self.enemy, 5);
  749.         else if (self.watertype == CONTENT_SLIME)
  750.                        T_Damage (self,world, self.enemy, 1);
  751.  
  752.         if(self.bloodloss>0)
  753.                 Bleed();
  754.  
  755.         if ((self.charmed) && (self.enemy == self.controller||self.enemy==world))
  756.                 {
  757.                 if (FindTarget())
  758.                 return;
  759.                 }
  760.  
  761.         movedist = dist/(self.mass + 1); // to make increase mass slow down monsters
  762. // see if the enemy is dead
  763.         if (((self.enemy.health <= 0 || (!self.enemy.alive))&&self.enemy.classname!="holo")||self.enemy.isfeign)
  764.             {
  765.         self.enemy = world;
  766.     // FIXME: look all around for other targets
  767.                 if (self.oldenemy.health > 0 && self.oldenemy.alive)
  768.         {
  769.             self.enemy = self.oldenemy;
  770.             HuntTarget ();
  771.         }
  772.         else
  773.         {
  774.             if (self.movetarget)
  775.                 self.th_walk ();
  776.             else
  777.                 self.th_stand ();
  778.             return;
  779.         }
  780.     }
  781.  
  782.     self.show_hostile = time + 1;        // wake up other monsters
  783.  
  784. // check knowledge of enemy
  785.     enemy_vis = visible(self.enemy);
  786.         if ((enemy_vis) && (self.enemy.alive))
  787.         self.search_time = time + 5;
  788.  
  789. // look for other coop players
  790.     if (coop && self.search_time < time)
  791.     {
  792.         if (FindTarget ())
  793.             return;
  794.     }
  795.  
  796.     enemy_infront = infront(self.enemy);
  797.     enemy_range = range(self.enemy);
  798.     enemy_yaw = vectoyaw(self.enemy.origin - self.origin);
  799.     
  800.     if (self.attack_state == AS_MISSILE)
  801.     {
  802. //dprint ("ai_run_missile\n");
  803.         ai_run_missile ();
  804.         return;
  805.     }
  806.     if (self.attack_state == AS_MELEE)
  807.     {
  808. //dprint ("ai_run_melee\n");
  809.         ai_run_melee ();
  810.         return;
  811.     }
  812.  
  813.     if (CheckAnyAttack ())
  814.         return;                    // beginning an attack
  815.         
  816.     if (self.attack_state == AS_SLIDING)
  817.     {
  818.         ai_run_slide ();
  819.         return;
  820.     }
  821.         
  822. // head straight in
  823.     movetogoal (dist);        // done in C code...
  824. };
  825.  
  826.